import storage from '@system.storage';
import prompt from '@system.prompt';

const TAG = 'fa_demo_tag # ';
const DEBUG = true;

const FaUtils = {
    isNUll(value) {
        if (!value || value === null || value === undefined) {
            return true;
        }
        return false;
    },
    isNotNUll(value) {
        if (value && value !== null && value !== undefined) {
            return true;
        }
        return false;
    },
    storageGet(key, callback) {
        storage.get({
            key,
            success: value => {
                callback(value);
            },
        });
    },
    storageSet(key, value, callback) {
        storage.set({
            key,
            value,
            success: () => {
                callback();
            },
        });
    },
    logInfo(msg) {
        if (DEBUG) {
            console.info(TAG + msg);
        }
    },
    logError(msg) {
        if (DEBUG) {
            console.error(TAG + msg);
        }
    },
    toast(msg, time = 1000) {
        prompt.showToast({
            message: msg,
            duration: time,
        });
    },
};

export default FaUtils;